﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeCamp12.DAL;
using CodeCamp12.Domain;
using log4net;

namespace CodeCamp12.BLL
{
    public class AnnouncementsBL
    {
        private ILog log = LogManager.GetLogger("CodeCamp12.BLL"); 

        #region Announcements

        /// <summary>
        /// Insert new announcement for the website
        /// </summary>
        /// <param name="announcement"></param>
        public void InsertAnnouncement(Announcements announcement)
        {
            var annoouncementDataProvider = new AnnouncementDataManagement();
            try
            {
                annoouncementDataProvider.InsertAnnouncement(announcement);
            }
            catch(Exception ex)
            {
                 
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Update existing announcement from website
        /// </summary>
        /// <param name="announcement"></param>
        public void UpdateAnnouncement(Announcements announcement)
        {
            var announcementDataProvicer = new AnnouncementDataManagement();
            try
            {
                announcementDataProvicer.UpdateAnnouncement(announcement);
            }
            catch(Exception ex)
            {
                 
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Delete announcement from website
        /// </summary>
        /// <param name="announcement"></param>
        public void DeleteAnnouncement(Announcements announcement)
        {
            var announcementDataProvicer = new AnnouncementDataManagement();
            try
            {
                announcementDataProvicer.DeleteAnnouncement(announcement);
            }
            catch(Exception ex)
            {
                 
                log.Error(ex);
                throw;
            }
        }


        /// <summary>
        /// Get all announcements for the website
        /// </summary>
        /// <returns>Announcements</returns>
        public List<Announcements> GetAllAnnouncements()
        {
            var announcementsDataProvide = new AnnouncementDataManagement();
            try
            {
                return announcementsDataProvide.GetAllAnnouncements();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
            
        }

        /// <summary>
        /// Get announcement by id
        /// </summary>
        /// <param name="annId"></param>
        /// <returns>Announcements</returns>
        public Announcements GetAnnouncementById(Guid annId)
        {
            
            var announcementDataProvider = new AnnouncementDataManagement();
            try
            {
                return announcementDataProvider.GetAnnouncementById(annId);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
            
        }
        
        #endregion
        
        #region Notifications
       
        /// <summary>
        /// Insert new home page notification
        /// </summary>
        /// <param name="notification"></param>
        public void InsertNotification(Notification notification)
        {
            
            var announsmentsDataProvider = new AnnouncementDataManagement();
            try
            {
                announsmentsDataProvider.InsertNotification(notification);
            }
            catch(Exception ex)
            {
                 
                log.Error(ex);  
                throw;
            }
        }

        /// <summary>
        ///  Delete existing home page notification
        /// </summary>
        /// <param name="notification"></param>
        public void DeleteNotification(Notification notification)
        {   
            var announcementsDataProvider = new AnnouncementDataManagement();
            try
            {
                announcementsDataProvider.DeleteNotification(notification);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Get all home page notifications
        /// </summary>
        /// <returns>Notification</returns>
        public List<Notification> GetAllNotifications()
        {
            var announsementsDataProvider = new AnnouncementDataManagement();
            List<Notification> notificationList = null;
            try
            {
                notificationList = announsementsDataProvider.GetAllNotifications();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
            return notificationList;
        }

        #endregion
    }
}
